package com.framework.modules.live.controller;

import java.util.HashMap;
import java.util.Map;

import com.framework.common.annotation.Login;
import com.framework.common.config.SystemConfigName;
import com.framework.common.utils.HttpContextUtils;
import com.framework.common.utils.QuickHelper;
import com.framework.modules.dataview.service.ViewUserInfoLiveService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.bind.annotation.*;

import com.framework.modules.live.service.LiveRoomService;
import com.framework.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 直播室信息 
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-29 13:40:34
 */
@RestController
@RequestMapping("/live")
@DependsOn("databaseInitConfig")
@Api(tags = "直播接口")
public class LiveRoomController {
    @Autowired
    private LiveRoomService liveRoomService;


    @Autowired
    private ViewUserInfoLiveService viewUserInfoLiveService;
    /**
     *直播/直播详情
     * 数据库 [ 直播室信息  ]  tb_live_room
     * @return
     * {
     *      *   "msg": "success",
     *      *   "code": 1,
     *      *   "data": {
     *      *     "coverImage": "https://app-dev-1301591806.cos.ap-shanghai.myqcloud.com/images/20201214/c5e3655f38d14dd89ea76308f55058c0.png",//直播封面
     *      *     "endDate": 1608731438,//直播结束时间
     *      *     "forbiddenEndTime": 0,//封禁时间
     *      *     "forbiddenMsg": "您的直播室由于相关原因被禁止直播，若有疑问，请联系客服人员 !",//封禁原因
     *      *     "giftCount": 0,//累计礼物数
     *      *     "liveRoundId": "live_20122313494800000009",//直播场次
     *      *     "onlineCount": 0,//在线人数
     *      *     "password": "",//直播间密码
     *      *     "popCount": 0,//人气值
     *      *     "rank": 0,//推荐
     *      *     "snapshotImage": "http://app-dev-1301591806.cos.ap-shanghai.myqcloud.com/snapshot/test/1-screenshot-21-50-25-544x960.jpg",//直播截图
     *      *     "startDate": 1608731388,//直播开始时间
     *      *     "state": 0,//直播状态 直播=1,未直播=0,禁播=-1,断播=-2
     *      *     "title": "哈喽哈喽",//直播标题
     *      *     "totalSeconds": 6069,//直播时间
     *      *     "uid": 1
     *      *   }
     *      * }
     */
    @Login
    @GetMapping("/get_live_item")
    @ApiOperation("直播详情 ")
    public R getLiveItem(Long uid){
        if(uid==null){
            return R.error("请登录");
        }
        Object object=liveRoomService.findLiveInfo(uid.intValue());
        return R.ok(object);
    }

    @Login
    @GetMapping("/get_my_live_room_info")
    @ApiOperation("获取我的直播详情")
    public R getMyLiveRoomInfo(){
        Long uid = (Long) HttpContextUtils.getHttpServletRequestHeaderValue("uid");
        if(uid==null){
            return R.error("请登录");
        }
        Object object=liveRoomService.findLiveInfo(uid.intValue());
        return R.ok(object);
    }



    /**
     *直播/直播列表
     * 数据库 [ 直播室信息  ]  tb_live_room
     * @param page 页码
     * @param query 用户昵称或友街id
     * @return
     * online_count 在线人数
     * total_seconds 累计直播时间
     * cover_image 直播封面
     * title 直播标题
     * popCount 人气
     * rank 是否推荐 数字越高，推荐级别越高
     * state 直播状态 直播=1,未直播=0,禁播=-1
     */
    @Login
    @GetMapping("/get_live_list")
    @ApiOperation("直播列表")
    public R getLiveList(Integer page,String query){
        Long uid = (Long) HttpContextUtils.getHttpServletRequestHeaderValue("uid");
        if(uid==null){
            return R.error("请登录");
        }
        Map<String, Object> params=new HashMap<>();
        params.put("page",page.toString());
        params.put("limit",QuickHelper.getConfigString(SystemConfigName.RECORD_POST_PAGE_COUNT));
        if(StringUtils.isNotBlank(query)){
            params.put("query",query);
        }
        Object object=viewUserInfoLiveService.queryPage(params);
        return R.ok(object);
    }


}
